import org.xu.utils.Base64Util;

import java.io.*;

/**
 * 拼sql
 */
public class PDFTest3 {

    public static void main(String[] args) throws IOException {

        System.out.println("----===========");
        String inFileName = "D:\\PDF_test\\测试PDF_1.pdf";
        File file = new File("D:\\tmp\\回单_测试.pdf");
        if (!file.exists()){
            file.createNewFile();
        }
        File txtFile = new File("D:\\tmp\\回单_字符串自测.txt");
        if (!txtFile.exists()){
            txtFile.createNewFile();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        FileOutputStream fileOutputStream2 = new FileOutputStream(txtFile);
        StringBuffer buf = new StringBuffer();
        try(FileInputStream fileInputStream = new FileInputStream(new File(inFileName))) {
            while (true) {
                byte[] datas = new byte[1024];
                int length = fileInputStream.read(datas);
                if (length <= 0) {
                    break;
                }
                // 获取数据
                for (int i = 0; i < datas.length; i++) {
                    fileOutputStream.write(datas[i]);
                    fileOutputStream2.write(datas[i]);
                }
                buf.append(new String(datas));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            fileOutputStream.close();
            fileOutputStream2.close();
        }
        System.out.println("==========");
        String strEncode = Base64Util.encode(buf.toString());
        System.out.println(strEncode);
    }

}
